﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AutoMapper;
using WebStore.Web.App.Models.Cart;

namespace WebStore.Web.App.Controllers
{
    public partial class CartController
    {
        [Authorize]
        public ViewResult Orders()
        {
            return View(new OrdersModel { Orders = CurrentUser.Orders.Select(Mapper.Map<OrderModel>) });
        }

        [Authorize]
        public ActionResult Order(int id)
        {
            if(!CurrentUser.Orders.Any(x=>x.Id==id))
                return HttpNotFound();

            return View(Mapper.Map<OrderModel>(CurrentUser.Orders.FirstOrDefault(x => x.Id == id)));
        }
    }
}